package com.fr.report;

import com.fr.base.FCloneable;
import com.fr.base.Painter;
import com.fr.base.Style;
import com.fr.base.background.ColorBackground;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.GraphHelper;
import com.fr.base.core.html.Html;
import com.fr.base.core.html.Tag;
import com.fr.base.core.serializable.ImageSerializable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.ChartPainter;
import com.fr.report.cellElement.CellExpandAttr;
import com.fr.report.cellElement.CellGUIAttr;
import com.fr.report.cellElement.CellInsertPolicyAttr;
import com.fr.report.cellElement.CellPageAttr;
import com.fr.report.cellElement.Formula;
import com.fr.report.cellElement.Present;
import com.fr.report.core.PaintUtils;
import com.fr.report.highlight.HighlightGroup;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.io.xml.SynchronizedStyleList;
import com.fr.report.js.NameJavaScriptGroup;
import com.fr.report.web.ui.Widget;
import com.fr.web.Repository;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Iterator;

public class FloatElement
  implements Elem, XMLReadable, Cloneable, Serializable
{
  private static int index = 0;
  private String name;
  private int row;
  private int column;
  private int leftDistance;
  private int topDistance;
  private Dimension size;
  private transient Object value;
  private Style style;
  private NameJavaScriptGroup nameHyperlinkGroup;

  public FloatElement()
  {
    this("");
  }

  public FloatElement(Object paramObject)
  {
    this(0, 0, 0, 0, new Dimension(100, 100), paramObject);
  }

  public FloatElement(int paramInt1, int paramInt2, Object paramObject)
  {
    this(paramInt1, paramInt2, 0, 0, paramObject);
  }

  public FloatElement(int paramInt1, int paramInt2, int paramInt3, int paramInt4, Object paramObject)
  {
    this(paramInt1, paramInt2, paramInt3, paramInt4, new Dimension(100, 100), paramObject);
  }

  public FloatElement(int paramInt1, int paramInt2, int paramInt3, int paramInt4, Dimension paramDimension, Object paramObject)
  {
    this.name = "";
    this.row = 0;
    this.column = 0;
    this.leftDistance = 0;
    this.topDistance = 0;
    this.size = new Dimension(100, 100);
    this.value = null;
    this.style = null;
    this.nameHyperlinkGroup = null;
    this.name = "Float" + (index++);
    setRow(paramInt2);
    setColumn(paramInt1);
    setLeftDistance(paramInt3);
    setTopDistance(paramInt4);
    setSize(paramDimension);
    setValue(paramObject);
    this.style = Style.getInstance();
    this.style = this.style.deriveBackground(ColorBackground.getInstance(Color.WHITE));
    this.style = this.style.deriveBorder(1, Color.black, 1, Color.black, 1, Color.black, 1, Color.black);
  }

  public String getName()
  {
    return this.name;
  }

  public int getRow()
  {
    return this.row;
  }

  public void setRow(int paramInt)
  {
    this.row = paramInt;
  }

  public int getColumn()
  {
    return this.column;
  }

  public void setColumn(int paramInt)
  {
    this.column = paramInt;
  }

  public int getLeftDistance()
  {
    return this.leftDistance;
  }

  public void setLeftDistance(int paramInt)
  {
    this.leftDistance = paramInt;
  }

  public int getTopDistance()
  {
    return this.topDistance;
  }

  public void setTopDistance(int paramInt)
  {
    this.topDistance = paramInt;
  }

  public Dimension getSize()
  {
    return this.size;
  }

  public void setSize(Dimension paramDimension)
  {
    this.size = paramDimension;
  }

  public Object getValue()
  {
    return this.value;
  }

  public void setValue(Object paramObject)
  {
    this.value = paramObject;
  }

  public Style getStyle()
  {
    if (this.style == null)
      this.style = Style.DEFAULT_STYLE;
    return this.style;
  }

  public void setStyle(Style paramStyle)
  {
    this.style = paramStyle;
  }

  public NameJavaScriptGroup getNameHyperlinkGroup()
  {
    return this.nameHyperlinkGroup;
  }

  public void setNameHyperlinkGroup(NameJavaScriptGroup paramNameJavaScriptGroup)
  {
    this.nameHyperlinkGroup = paramNameJavaScriptGroup;
  }

  public Tag toTag(Repository paramRepository)
  {
    Object localObject;
    int i = (int)getSize().getWidth();
    int j = (int)getSize().getHeight();
    Tag localTag = null;
    if (getValue() instanceof ChartPainter)
    {
      localObject = new Tag("td");
      localTag = new Tag("table").cls("x-chart-table").sub(new Tag("tr").sub((Html)localObject));
      ((ChartPainter)getValue()).paintTag(paramRepository, i, j, this.style, (Tag)localObject, this);
    }
    else
    {
      localObject = GraphHelper.createBufferedImage(i, j, 6);
      Graphics2D localGraphics2D = ((BufferedImage)localObject).createGraphics();
      localGraphics2D.setPaint(Color.white);
      PaintUtils.paintFloatElement(localGraphics2D, this, i - 1, j - 1);
      ((BufferedImage)localObject).flush();
      localGraphics2D.dispose();
      localTag = paramRepository.checkoutImageTag((Image)localObject, i, j);
    }
    return ((Tag)localTag);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1;
      String str2 = paramXMLableReader.getTagName();
      if ("Location".equals(str2))
      {
        if ((str1 = paramXMLableReader.getAttr("column")) != null)
          setColumn(Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getAttr("row")) != null)
          setRow(Integer.parseInt(str1));
        if ((str1 = paramXMLableReader.getAttr("leftDistance")) != null)
          setLeftDistance((int)Double.parseDouble(str1));
        if ((str1 = paramXMLableReader.getAttr("topDistance")) != null)
          setTopDistance((int)Double.parseDouble(str1));
        int i = 0;
        int j = 0;
        if ((str1 = paramXMLableReader.getAttr("width")) != null)
          i = (int)Double.parseDouble(str1);
        if ((str1 = paramXMLableReader.getAttr("height")) != null)
          j = (int)Double.parseDouble(str1);
        setSize(new Dimension(i, j));
      }
      else if (str2.equals("Style"))
      {
        if ((str1 = paramXMLableReader.getAttr("index")) != null)
          SynchronizedStyleList.getSynchronizedStyleList(Thread.currentThread()).put(Integer.parseInt(str1), this);
      }
      else if (("NameJavaScriptGroup".equals(str2)) || ("NameJavaScriptGroup".equals(str2)) || ("NameHyperlinks".equals(str2)) || ("HyperlinkMap".equals(str2)))
      {
        NameJavaScriptGroup localNameJavaScriptGroup = new NameJavaScriptGroup();
        paramXMLableReader.readXMLObject(localNameJavaScriptGroup);
        setNameHyperlinkGroup(localNameJavaScriptGroup);
      }
      else if (("O".equals(str2)) || ("Object".equals(str2)))
      {
        setValue(ReportXMLUtils.readObject(paramXMLableReader, true, null));
      }
      else if ("Hyperlink".equals(str2))
      {
        setNameHyperlinkGroup(new NameJavaScriptGroup(ReportXMLUtils.readJavaScript(paramXMLableReader)));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Location").attr("column", getColumn()).attr("row", getRow()).attr("leftDistance", getLeftDistance()).attr("topDistance", getTopDistance()).attr("width", getSize().getWidth()).attr("height", getSize().getHeight()).end();
    ReportXMLUtils.writeObject(paramXMLPrintWriter, getValue());
    if ((this.style != null) && (!(ComparatorUtils.equals(this.style, Style.DEFAULT_STYLE))))
      ReportXMLUtils.writeIndexStyle(paramXMLPrintWriter, this.style);
    if (getNameHyperlinkGroup() != null)
      getNameHyperlinkGroup().writeXML(paramXMLPrintWriter);
  }

  private void readObject(ObjectInputStream paramObjectInputStream)
    throws ClassNotFoundException, IOException
  {
    paramObjectInputStream.defaultReadObject();
    Object localObject = paramObjectInputStream.readObject();
    if (localObject != null)
      if (localObject instanceof ImageSerializable)
        this.value = ((ImageSerializable)localObject).getImage();
      else
        this.value = localObject;
  }

  private void writeObject(ObjectOutputStream paramObjectOutputStream)
    throws IOException
  {
    paramObjectOutputStream.defaultWriteObject();
    if ((this.value != null) && (this.value instanceof Image))
    {
      ImageSerializable localImageSerializable = new ImageSerializable((Image)this.value);
      paramObjectOutputStream.writeObject(localImageSerializable);
    }
    else
    {
      paramObjectOutputStream.writeObject(this.value);
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    FloatElement localFloatElement = (FloatElement)super.clone();
    localFloatElement.name = "Float" + (index++);
    if (getValue() != null)
      if (getValue() instanceof Formula)
        localFloatElement.setValue(((Formula)getValue()).clone());
      else if (getValue() instanceof Painter)
        localFloatElement.setValue(((Painter)getValue()).clone());
    if (getSize() != null)
    {
      Dimension localDimension = getSize();
      localFloatElement.setSize((Dimension)localDimension.clone());
    }
    if (getNameHyperlinkGroup() != null)
      localFloatElement.setNameHyperlinkGroup((NameJavaScriptGroup)getNameHyperlinkGroup().clone());
    if (this.style != null)
      localFloatElement.setStyle((Style)this.style.clone());
    return localFloatElement;
  }

  public FloatElement deriveFloatElement(int paramInt1, int paramInt2, int paramInt3, int paramInt4, Dimension paramDimension)
    throws CloneNotSupportedException
  {
    FloatElement localFloatElement = (FloatElement)super.clone();
    localFloatElement.setColumn(paramInt1);
    localFloatElement.setRow(paramInt2);
    localFloatElement.setLeftDistance(paramInt3);
    localFloatElement.setTopDistance(paramInt4);
    localFloatElement.setSize(paramDimension);
    return localFloatElement;
  }

  public Iterator attributeKeyIterator()
  {
    throw new UnsupportedOperationException();
  }

  public Object getAttribute(Object paramObject)
  {
    throw new UnsupportedOperationException();
  }

  public CellExpandAttr getCellExpandAttr()
  {
    throw new UnsupportedOperationException();
  }

  public CellGUIAttr getCellGUIAttr()
  {
    throw new UnsupportedOperationException();
  }

  public CellPageAttr getCellPageAttr()
  {
    throw new UnsupportedOperationException();
  }

  public CellInsertPolicyAttr getCellInsertPolicyAttr()
  {
    throw new UnsupportedOperationException();
  }

  public Widget getWidget()
  {
    throw new UnsupportedOperationException();
  }

  public HighlightGroup getHighlightGroup()
  {
    throw new UnsupportedOperationException();
  }

  public Present getPresent()
  {
    throw new UnsupportedOperationException();
  }

  public String getScript()
  {
    throw new UnsupportedOperationException();
  }

  public Object removeAttribute(Object paramObject)
  {
    throw new UnsupportedOperationException();
  }

  public void setAttribute(Object paramObject1, Object paramObject2)
  {
    throw new UnsupportedOperationException();
  }

  public void setCellExpandAttr(CellExpandAttr paramCellExpandAttr)
  {
    throw new UnsupportedOperationException();
  }

  public void setCellGUIAttr(CellGUIAttr paramCellGUIAttr)
  {
    throw new UnsupportedOperationException();
  }

  public void setCellPageAttr(CellPageAttr paramCellPageAttr)
  {
    throw new UnsupportedOperationException();
  }

  public void setCellInsertPolicyAttr(CellInsertPolicyAttr paramCellInsertPolicyAttr)
  {
    throw new UnsupportedOperationException();
  }

  public void setWidget(Widget paramWidget)
  {
    throw new UnsupportedOperationException();
  }

  public void setHighlightGroup(HighlightGroup paramHighlightGroup)
  {
    throw new UnsupportedOperationException();
  }

  public void setPresent(Present paramPresent)
  {
    throw new UnsupportedOperationException();
  }

  public void setScript(String paramString)
  {
    throw new UnsupportedOperationException();
  }
}